package hot;

public class sisanqi {
//    https://leetcode.cn/problems/path-sum-iii/?envType=study-plan-v2&envId=top-100-liked
    public class TreeNode {
     int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
    class Solution {
        int count=0;
        int    targetSum=0;
        public int pathSum(TreeNode root, int _targetSum) {
            targetSum=_targetSum;
            travel(root);
            return count;
        }
        public void travel(TreeNode root){
            if(root==null){return;}
            dfs(root,0);
            travel(root.left);
            travel(root.right);
        }
        public void dfs(TreeNode root,long currentSum){
            if(root==null){return;}
            currentSum+=root.val;
            if(targetSum==currentSum){count++;}
            dfs(root.left,currentSum);
            dfs(root.right,currentSum);







        }
    }
}
